package cn.fzc.yipai.controller;

import cn.fzc.yipai.entity.Account;
import cn.fzc.yipai.entity.NewGoodsInfo;
import cn.fzc.yipai.entity.StoreInfo;
import cn.fzc.yipai.service.AccountService;
import cn.fzc.yipai.service.GoodsListService;
import cn.fzc.yipai.service.StoreInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @Author: fu.zc
 * @Date: 2021/7/18 10:50
 * @Description:
 */
@Controller
public class IndexController {


    private final AccountService accountService;
    private final GoodsListService goodsListService;
    private final StoreInfoService storeInfoService;

    @Autowired
    public IndexController(AccountService accountService, GoodsListService goodsListService, StoreInfoService storeInfoService) {
        this.accountService = accountService;
        this.goodsListService = goodsListService;
        this.storeInfoService = storeInfoService;
    }


    @GetMapping("index")
    public String index(Model model) {
        List<NewGoodsInfo> goodsList = goodsListService.getLocalGoodsList();
        List<StoreInfo> storeInfoList = storeInfoService.list();
        List<Account> accountList = accountService.list();
        model.addAttribute("goodsList", goodsList);
        model.addAttribute("storeInfoList", storeInfoList);
        model.addAttribute("accountList", accountList);
        return "index";
    }

}
